package www.geek.filemanager.fragments;


import android.util.Log;
import android.util.SparseArray;

import www.geek.filemanager.base.BaseFragment;

/**
 * 
 *  Fragment工厂类，统一处理整个工程中的Fragment——用于Fragment的生成，管理
 *
 * @author 		: zhanggeng
 * @date  			: 2015-7-28
 * @version		: v1.0
 * ----------修订历史-----------
 *
 */
public class FragmentFactory {

	//应用管理界面标识
	public static final int TAB_APP_SYSTEM= 0;
	public static final int TAB_APP_USER = 1;
	//资源管理界面标识
	public static final int TAB_RES__PIC = 2;
	public static final int TAB_RES__VIDEO = 3;
	public static final int TAB_RES__MUSIC = 4;
	public static final int TAB_RES__TEXT = 5;
	public static final int TAB_RES__FILE = 6;

	
	/** 记录所有的fragment，防止重复创建 */
	private static SparseArray<BaseFragment>  mFragmentMap = new SparseArray<BaseFragment>();

	/** 采用工厂类进行创建Fragment，便于扩展，已经创建的Fragment不再创建 */
	public static BaseFragment createFragment(int index) {

		Log.i("index" , index + "");

		BaseFragment fragment = mFragmentMap.get(index);
		
		if (fragment == null) {
			switch (index) {
				case TAB_APP_SYSTEM:
					fragment = new SystemAppFragment();
					return fragment;
				case TAB_APP_USER:
					fragment = new UserAppFragment();
					return fragment;
				case TAB_RES__PIC:
					fragment = new PicResFragment();
					return fragment;
				case TAB_RES__VIDEO:
					fragment = new VideoResFragment();
					return fragment;
				case TAB_RES__MUSIC:
					fragment = new MusicResFragment();
					return fragment;
				case TAB_RES__TEXT:
					fragment = new TextResFragment();
					return fragment;
				case TAB_RES__FILE :
					fragment = new FileResFragment();
					return fragment;
			}
			mFragmentMap.put(index, fragment);
		}
		return fragment;
	}
}
